package lambda;


import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author Klys
 * @Date 2023/4/25 22:40
 * @Description
 * @Version 1.0
 */
public class Demo02 {

    public static void main(String[] args) {

//        List<String> list= Arrays.asList("1","0","1");
//        ArrayList<String> arrayList = new ArrayList<>();
//
//        for (String element:list
//             ) {
//            if (element.startsWith("k")){
//                arrayList.add(element);
//            }
//        }

        //lambda表达式
//        List<String> k = list.stream().filter(a -> a.equals("1")).map(a->a="klys").collect(Collectors.toList());
//        System.out.println(k);


        User user1 = new User("1");
        User user2 = new User("1");
        User user3 = new User("0");
        List<User> list = Arrays.asList(user1, user2, user3);

        List<User> collect = list.stream().map(a -> {
            if (a.getName().equals("1")) {
                a.setName("klys");
            }
            return a;
        }).collect(Collectors.toList());

        for (User user : collect
        ) {
            System.out.println(user.toString());
        }


    }
}
